class PdsessionsController < ApplicationController
  before_filter :login_required, :only => [ :index, :show ]
  before_filter :admin_login_required, :only => [ :new, :edit, :create, :update, :destroy ]

  def index
    page = params[:page] || 1
    @pdsessions = Pdsession.paginate :page => page, :order => 'start DESC'
    @attending = @pdsessions & current_user.pdsessions
    @notattending = @pdsessions - @attending
  end

  def show
    @pdsession = Pdsession.find(params[:id])
    @attendees = @pdsession.users
  end

  def new
    @pdsession = Pdsession.new
  end

  def edit
    @pdsession = Pdsession.find(params[:id])
  end

  def create
    @pdsession = Pdsession.new(params[:pdsession])

      if @pdsession.save
        flash[:notice] = 'PDSession was successfully created.'
        redirect_to(@pdsession)
      else
        render :action => "new"
      end
  end

  def update
    @pdsession = Pdsession.find(params[:id])
    if @pdsession.update_attributes(params[:pdsession])
      flash[:notice] = 'Post was successfully updated.'
      redirect_to(@pdsession)
    else
      render :action => "edit"
    end
  end

  def destroy
    @pdsession = Pdsession.find(params[:id])
    @pdsession.destroy
    redirect_to(pdsessions_url)
  end
  
  def attending?
    return false
  end
  helper_method :attending?
  
end
